
import { Render } from "./render.js";
import {Load } from "./loaddata.js";
import  {Carts} from "./carts.js";
class Details {
    constructor(){
     this.cash = "";
    }
    init() {
        this.carts = new Carts();
        let  data_arr = location.hash.split("#");
        let  good_id = data_arr[1];
        let  good_price = data_arr[2];
        let select = "";
        let temp = this;
        new Load().init()
        .then(res=>{
          let goods_list = res.data.goods_list_one;
           temp.cash = goods_list;
           console.log(temp.cash);
            // 对res里的商品进行筛选,留下那个id一致的商品信息;
            for(let i = 0,good; good = goods_list[i];i++){
                if(good.good_id == good_id){
                  select = good;
                  break;
                }
            }
        //渲染商品详情;
          let html   =  new Render().renderDetails(select);
          // console.log(html);
          let good_box = $(".good-details .w1200");
          good_box.html(html);

          //放大镜调用
          $("#exzoom").exzoom({
            autoPlay: false,
        });

        let close_btn = $(".close");
        let login_board = $(".login-ifranmes");

        let register_btn = $(".register-in");
        let login_btn = $(".login-in");
        //显示注册;
        register_btn.on("click", $.proxy(function () {
            login_board.children().eq(1).attr("src", "http://localhost/wuTuoJia_project/src/html/register.html");
            login_board.addClass("login-show");
            $("body").parent().css("overflow-y", "hidden");
        }, this))

        //显示登录;
        login_btn.on("click", $.proxy(function () {
            login_board.children().eq(1).attr("src", "http://localhost/wuTuoJia_project/src/html/login.html");
            login_board.addClass("login-show");
            $("body").parent().css("overflow-y", "hidden");
        }, this))

        //隐藏界面;
        close_btn.on("click", $.proxy(function () {
            login_board.removeClass("login-show");
            $("body").parent().css("overflow-y", "auto");
        }, this))

        })
        .then(evt=>{
            //渲染完之后再调用;
            this.carts.init();
            // console.log(this);
            this.carts.add(this.callRenCartList.bind(this),"render_list");
        })

    }

    callRenCartList(){
        //  console.log(this);
         let carts_list = $(".carts-list .goods-list");
         console.log(carts_list);
         let html =   new Render().renderCartsList(this.cash);
         carts_list.html(html);
    }








}

export default new Details();